<?php
class Hotels {

    public function listHotels() {
    	$db_obj = new DB();
    	/*$hotels_sql = "SELECT H.*, O.*,  OI.image_name
    				   FROM hotel as H
    				   LEFT JOIN offer AS O ON O.hotel_id = H.hotel_id
    				   LEFT JOIN offer_images AS OI ON OI.offer_id = O.offer_id
    				   WHERE OI.is_default = 1";*/
        $hotels_sql = "SELECT H.*, O.*
    				   FROM offer as O    				   
    				   LEFT JOIN hotel AS H ON O.hotel_id = H.hotel_id";

        
    	$db_obj->query($hotels_sql);
        if($db_obj->rowCount() > 0) {
            //$hotels_details = $db_obj->getResults($hotels_sql);
            $hotels_details = $db_obj->getResultsPagination($hotels_sql, 5);
            $pagination_links=$db_obj->renderFullNav();
            $extra_obj = new Extra();
            return array($extra_obj->objectToArray($hotels_details), $pagination_links);
        } else {
            return false;
        }
    }
    
    public function getCountryById($country_id) {
    	$db_obj = new DB();
    	$country_sql = "SELECT country_name, country_code
    					FROM country
    					WHERE country_id = " . $country_id;
    	$db_obj->query($country_sql);
    	if($db_obj->rowCount() > 0) {
            $country = $db_obj->getResults($country_sql);
            $extra_obj = new Extra();
            return $extra_obj->objectToArray($country);
        } else {
            return false;
        }
    }
    
    public function insert_hotel($hotel_details) {
    	$db_obj = new DB();
        $table = 'hotel';
        $db_obj->insert($table, $hotel_details);
        return  $db_obj->getLastInsertId();
    }
    
    public function update_hotel($hotel_details, $hotel_id) {
        $db_obj = new DB();
        $table = 'hotel';
        $data = $hotel_details;
        $where = array("hotel_id =" . $hotel_id );        
        $db_obj->update($table, $data, $where);
    }
    
    public function get_hotels($id='') {
    	$db_obj = new DB();
        if(!empty($id)){
            $where=" WHERE hotel_id=".$id;
        }
    	$hotels_sql = "SELECT * FROM hotel {$where}";
    	$db_obj->query($hotels_sql);
        if($db_obj->rowCount() > 0) {
            $hotels_details = $db_obj->getResults($hotels_sql);
            $extra_obj = new Extra();
            return $extra_obj->objectToArray($hotels_details);
        } else {
            return false;
        }
    }
    
    public function remove_hotel($id=0) {
    	$db_obj = new DB();           	
        $talble='hotel';
        $where=array("hotel_id =" . $id );
    	$db_obj->delete($talble, $where);        
    }
}
?>
